package cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.impl;

import cn.zane.designPattern.createPatterns.factoryMethodPatterns.design.store.ICommodity;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.oldCode.goods.DeliverReq;
import cn.zane.designPattern.createPatterns.factoryMethodPatterns.oldCode.goods.GoodsService;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @Author: zane
 * @Date: 2024/12/25
 * @Description: 商品：实物商品服务
 */
@Slf4j
public class GoodsCommodityService implements ICommodity {

    // 模拟注入
    private GoodsService goodsService = new GoodsService();

    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryUserName(uId));
        deliverReq.setUserPhone(queryUserPhoneNumber(uId));
        deliverReq.setSku(commodityId);
        deliverReq.setConsigneeUserName(extMap.get("consigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("consigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("consigneeUserAddress"));
        Boolean isSuccess = goodsService.deliverGoods(deliverReq);
        log.info("请求参数[实物商品]->uId:{} commodityId:{} bizId:{} extMap:{}", uId, commodityId, bizId, JSON.toJSONString(extMap));
        log.info("测试结果[实物商品]:{}", isSuccess);
        if (!isSuccess) {
            throw new RuntimeException("实物商品发放失败");
        }
    }

    private String queryUserName(String uId) {
        return "zane";
    }

    private String queryUserPhoneNumber(String uId) {
        return "01234567891";
    }
}
